<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<script type="text/javascript">

//单击事件
function ZtreeClick(event, treeId, treeNode) {
    event.preventDefault()
    var $detail = $('#ztree-detail')
	if (treeNode.name) $('#j_menu_name').val(treeNode.name)
	if (treeNode.url) {
		$('#j_menu_url').val(treeNode.url)
	} else {
		$('#j_menu_url').val('')
	}
	if (treeNode.rel) {
		$('#j_menu_tabid').val(treeNode.rel)
	} else {
		$('#j_menu_tabid').val('')
	}	
	try
	{
	
	if(treeNode.id)
	{
		$('#j_menu_ucode').val(treeNode.id)
	}
	else
	{
		$('#j_menu_ucode').val('')
	}
	if(treeNode.target)
	{
		$('#j_menu_target').val(treeNode.target)
	}
	else
	{
		$('#j_menu_target').val("")
	}
	if(treeNode.utype)
	{
		$('#j_menu_utype').val(treeNode.utype)
	}
	else
	{
		$('#j_menu_utype').val("")
	}
	if(treeNode.pid)
	{
		$('#j_menu_parent').val(treeNode.pid)
	}
	else
	{
		$('#j_menu_parent').val('');
	}
	if(treeNode.category)
	{
		$('#j_menu_category').val(treeNode.category)
	}
	else
	{
		$('#j_menu_category').val('');
	}
	if(treeNode.isort)
	{
		$('#j_menu_isort').val(treeNode.isort)
	}
	else
	{
		$('#j_menu_isort').val('');
	}
	if(treeNode.memo)
	{
		$('#j_menu_memo').val(treeNode.memo)
	}
	else
	{
		$('#j_menu_memo').val('');
	}
	if(treeNode.cdesc)
	{
		$('#j_menu_cdesc').val(treeNode.cdesc)
	}
	else
	{
		$('#j_menu_cdesc').val('');
	}
	}catch(e){alert(e.message);}
	$detail.attr('id', treeNode.id)
    $detail.show()
}
//保存属性
function M_new_Menu() {
	if(checkForm())
	{
	
		$.CurrentNavtab.find("#menuForm").attr("action","<%=request.getContextPath()%>/menu/insert.do");
		$.CurrentNavtab.find("#menuForm").submit();
	}

}
function M_edit_Menu() {
	var ucode   = $('#j_menu_ucode').val();
	if ($.trim(ucode).length == 0) {
		$(this).alertmsg('error', '请点击要修改的功能或者操作')
		return false;
	}
	if(checkForm())
	{
	
		$.CurrentNavtab.find("#menuForm").attr("action","<%=request.getContextPath()%>/menu/update.do");
		$.CurrentNavtab.find("#menuForm").submit();
	}

}
function M_del_Menu() {
	var ucode   = $('#j_menu_ucode').val();
	if ($.trim(ucode).length == 0) {
		$(this).alertmsg('error', '请点击要删除的功能或者操作')
		return false;
	}
	if(checkForm())
	{
	
		$.CurrentNavtab.find("#menuForm").attr("action","<%=request.getContextPath()%>/menu/delete.do");
		$.CurrentNavtab.find("#menuForm").submit();
	}

}
function M_add_Menu() {
	var ucode   = $('#j_menu_ucode').val();
	if ($.trim(ucode).length == 0) {
		$(this).alertmsg('error', '请点击要删除的功能或者操作')
		return false;
	}
	$('#j_menu_parent').val(ucode);
	$('#j_menu_ucode').val("");
	$('#j_menu_name').val("")
	$('#j_menu_url').val("")
	$('#j_menu_tabid').val("")
	$('#j_menu_target').val("")
	$('#j_menu_utype').val("2")
	$('#j_menu_isort').val("")
	$('#j_menu_cdesc').val("")
	$('#j_menu_memo').val("")

}
function checkForm()
{
	var name   = $('#j_menu_name').val()
	var url    = $('#j_menu_url').val()
	var tabid  = $('#j_menu_tabid').val()
	var target = $('#j_menu_target').val()
	var category = $('#j_menu_utype').val()
	var isort = $('#j_menu_isort').val()

	if ($.trim(name).length == 0) {
		$(this).alertmsg('error', '名称不能为空！')
		return false;
	}
	if ($.trim(url).length == 0) {
		$(this).alertmsg('error', '请求URL不能为空！')		
		return false;
	}
	if ($.trim(tabid).length == 0) {
		$(this).alertmsg('error', 'tabid不能为空！')	
		
		return false;
	}
	if ($.trim(target).length == 0) {
		$(this).alertmsg('error', '打开方式不能为空！')	
		
		return false;
	}
	if ($.trim(category).length == 0) {
		$(this).alertmsg('error', '菜单类型不能为空！')	
		
		return false;
	}
	if ($.trim(isort).length == 0) {
		$(this).alertmsg('error', '排序序号不能为空！')	
		
		return false;
	}
	
	return true
}
</script>
<div class="bjui-pageContent">
    <div style="padding:20px;">
        <div class="clearfix">
            <div style="float:left; padding:10px;width:280px; height:100%; overflow:auto;">
                <ul id="ztree1" class="ztree" data-toggle="ztree" data-expand-all="true" data-check-enable="false" data-on-click="ZtreeClick">                                        
                    <c:forEach items="${menuList}" var="menu">
                     <li data-id="${menu.ucode}" data-pid="${menu.parent}" data-uname="${menu.uname}" data-url="${menu.url}"
                     data-cdesc="${menu.cdesc}" data-target="${menu.target}" data-rel="${menu.rel}" data-category="${menu.category}"
                     data-isort="${menu.isort}" data-utype="${menu.utype}" data-memo="${menu.memo}" >${menu.uname}</li>
                     <c:if test="${not empty menu.child}">
                        <c:forEach items="${menu.child}" var="child">
                         <li data-id="${menu.ucode}" data-pid="${menu.parent}" data-uname="${menu.uname}" data-url="${menu.url}"
                     data-cdesc="${menu.cdesc}" data-target="${menu.target}" data-rel="${menu.rel}" data-category="${menu.category}"
                     data-isort="${menu.isort}" data-utype="${menu.utype}" data-memo="${menu.memo}" >${menu.uname}</li>
                        </c:forEach>
                     </c:if>
                    </c:forEach>
                </ul>
            </div>
            <form id="menuForm" name="menuForm"  data-toggle="validate" data-reload-navtab="true" action="">
            <div id="ztree-detail" style=" margin-left:280px; width:400px; height:100%;">
                <input type="hidden" name="ucode" id="j_menu_ucode" value=""/>
                <input type="hidden" name="parent" id="j_menu_parent" value=""/>
                <input type="hidden" name="category" id="j_menu_category" value="1"/>
                <div class="bs-example" data-content="详细信息">
                    <div class="form-group">
                        <label for="j_menu_name" class="control-label x85">名称：</label>
                        <input type="text" class="required" name="uname" id="j_menu_name" size="25" placeholder="名称" />
                    </div>
                    <div class="form-group">
                        <label for="j_menu_url" class="control-label x85">请求URL：</label>
                        <input type="text" class="required" name="url"  id="j_menu_url" size="25" placeholder="Url" />
                    </div>
                    <div class="form-group">
                        <label for="j_menu_tabid" class="control-label x85">tabid：</label>
                        <input type="text" class="required" name="rel" id="j_menu_tabid" size="25" placeholder="tabid" />
                    </div>
                    <div class="form-group">
                        <label for="j_menu_target" class="control-label x85">打开方式：</label>
                        <select class="selectpicker show-tick" name="target" id="j_menu_target" data-style="btn-default btn-sel" data-width="auto">
                            <option value="">请选择</option>
                            <option value="navTab">navTab</option>
                            <option value="dialog">dialog</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label for="j_menu_target" class="control-label x85">菜单类型：</label>
                        <select class="selectpicker show-tick" name="utype" class="required" id="j_menu_utype" data-style="btn-default btn-sel" data-width="auto">
                            <option value="">请选择</option>
                            <option value="1">菜单功能</option>
                            <option value="2">操作功能</option>
                        </select>
                    </div>
                     <div class="form-group">
                        <label for="j_menu_tabid" class="control-label x85">功能描述：</label>
                        <input type="text"  name="cdesc" id="j_menu_cdesc" size="25" placeholder="功能描述" />
                    </div>
                     <div class="form-group">
                        <label for="j_menu_tabid" class="control-label x85">备注：</label>
                        <input type="text"  name="memo" id="j_menu_memo" size="25" placeholder="备注" />
                    </div>
                    <div class="form-group">
                        <label for="j_menu_tabid" class="control-label x85">排序序号：</label>
                        <input type="text" class="required digits"  name="isort" id="j_menu_isort" size="25" placeholder="序号" />
                    </div>
                    <div class="form-group" style="padding-top:8px; border-top:1px #DDD solid;">
                        <label class="control-label x85"></label>
                        <button type="button" class="btn btn-green" onclick="M_new_Menu();">新建</button>
                        <button type="button" class="btn btn-green" onclick="M_add_Menu();">增加操作</button>
                        <button type="button" class="btn btn-green" onclick="M_edit_Menu();">修改</button>                        
                        <button type="button" class="btn btn-green" onclick="M_del_Menu();">删除</button>
                    </div>
                </div>
            </div>
            </form>
        </div>
       